home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / jpeglib5b / jpeglib.h < prev    next >
C/C++ Source or Header  |  1980-01-12  |  38KB  |  936 lines

  1. /*
  2.  * jpeglib.h
  3.  *
  4.  * Copyright (C) 1991-1994, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file defines the application interface for the JPEG library.
  9.  * Most applications using the library need only include this file,
  10.  * and perhaps jerror.h if they want to know the exact error codes.
  11.  */
  12.  
  13. #ifndef JPEGLIB_H
  14. #define JPEGLIB_H
  15.  
  16. /*
  17.  * First we include the configuration files that record how this
  18.  * installation of the JPEG library is set up.  jconfig.h can be
  19.  * generated automatically for many systems.  jmorecfg.h contains
  20.  * manual configuration options that most people need not worry about.
  21.  */
  22.  
  23. #ifndef JCONFIG_INCLUDED    /* in case jinclude.h already did */
  24. #include "jconfig.h"        /* widely used configuration options */
  25. #endif
  26. #include "jmorecfg.h"        /* seldom changed options */
  27.  
  28.  
  29. /* Version ID for the JPEG library.
  30.  * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
  31.  */
  32.  
  33. #define JPEG_LIB_VERSION  51    /* Version 5a */
  34.  
  35.  
  36. /* Various constants determining the sizes of things.
  37.  * All of these are specified by the JPEG standard, so don't change them
  38.  * if you want to be compatible.
  39.  */
  40.  
  41. #define DCTSIZE            8    /* The basic DCT block is 8x8 samples */
  42. #define DCTSIZE2        64    /* DCTSIZE squared; # of elements in a block */
  43. #define NUM_QUANT_TBLS      4    /* Quantization tables are numbered 0..3 */
  44. #define NUM_HUFF_TBLS       4    /* Huffman tables are numbered 0..3 */
  45. #define NUM_ARITH_TBLS      16    /* Arith-coding tables are numbered 0..15 */
  46. #define MAX_COMPS_IN_SCAN   4    /* JPEG limit on # of components in one scan */
  47. #define MAX_SAMP_FACTOR     4    /* JPEG limit on sampling factors */
  48. #define MAX_BLOCKS_IN_MCU   10    /* JPEG limit on # of blocks in an MCU */
  49.  
  50.  
  51. /* This macro is used to declare a "method", that is, a function pointer.
  52.  * We want to supply prototype parameters if the compiler can cope.
  53.  * Note that the arglist parameter must be parenthesized!
  54.  */
  55.  
  56. #ifdef HAVE_PROTOTYPES
  57. #define JMETHOD(type,methodname,arglist)  type (*methodname) arglist
  58. #else
  59. #define JMETHOD(type,methodname,arglist)  type (*methodname) ()
  60. #endif
  61.  
  62.  
  63. /* Data structures for images (arrays of samples and of DCT coefficients).
  64.  * On 80x86 machines, the image arrays are too big for near pointers,
  65.  * but the pointer arrays can fit in near memory.
  66.  */
  67.  
  68. typedef JSAMPLE FAR *JSAMPROW;    /* ptr to one image row of pixel samples. */
  69. typedef JSAMPROW *JSAMPARRAY;    /* ptr to some rows (a 2-D sample array) */
  70. typedef JSAMPARRAY *JSAMPIMAGE;    /* a 3-D sample array: top index is color */
  71.  
  72. typedef JCOEF JBLOCK[DCTSIZE2];    /* one block of coefficients */
  73. typedef JBLOCK FAR *JBLOCKROW;    /* pointer to one row of coefficient blocks */
  74. typedef JBLOCKROW *JBLOCKARRAY;        /* a 2-D array of coefficient blocks */
  75. typedef JBLOCKARRAY *JBLOCKIMAGE;    /* a 3-D array of coefficient blocks */
  76.  
  77. typedef JCOEF FAR *JCOEFPTR;    /* useful in a couple of places */
  78.  
  79.  
  80. /* Types for JPEG compression parameters and working tables. */
  81.  
  82.  
  83. /* DCT coefficient quantization tables. */
  84.  
  85. typedef struct {
  86.   /* This field directly represents the contents of a JPEG DQT marker.
  87.    * Note: the values are always given in zigzag order.
  88.    */
  89.   UINT16 quantval[DCTSIZE2];    /* quantization step for each coefficient */
  90.   /* This field is used only during compression.  It's initialized FALSE when
  91.    * the table is created, and set TRUE when it's been output to the file.
  92.    * You could suppress output of a table by setting this to TRUE.
  93.    * (See jpeg_suppress_tables for an example.)
  94.    */
  95.   boolean sent_table;        /* TRUE when table has been output */
  96. } JQUANT_TBL;
  97.  
  98.  
  99. /* Huffman coding tables. */
  100.  
  101. typedef struct {
  102.   /* These two fields directly represent the contents of a JPEG DHT marker */
  103.   UINT8 bits[17];        /* bits[k] = # of symbols with codes of */
  104.                 /* length k bits; bits[0] is unused */
  105.   UINT8 huffval[256];        /* The symbols, in order of incr code length */
  106.   /* This field is used only during compression.  It's initialized FALSE when
  107.    * the table is created, and set TRUE when it's been output to the file.
  108.    * You could suppress output of a table by setting this to TRUE.
  109.    * (See jpeg_suppress_tables for an example.)
  110.    */
  111.   boolean sent_table;        /* TRUE when table has been output */
  112. } JHUFF_TBL;
  113.  
  114.  
  115. /* Basic info about one component (color channel). */
  116.  
  117. typedef struct {
  118.   /* These values are fixed over the whole image. */
  119.   /* For compression, they must be supplied by parameter setup; */
  120.   /* for decompression, they are read from the SOF marker. */
  121.   int component_id;        /* identifier for this component (0..255) */
  122.   int component_index;        /* its index in SOF or cinfo->comp_info[] */
  123.   int h_samp_factor;        /* horizontal sampling factor (1..4) */
  124.   int v_samp_factor;        /* vertical sampling factor (1..4) */
  125.   int quant_tbl_no;        /* quantization table selector (0..3) */
  126.   /* These values may vary between scans. */
  127.   /* For compression, they must be supplied by parameter setup; */
  128.   /* for decompression, they are read from the SOS marker. */
  129.   int dc_tbl_no;        /* DC entropy table selector (0..3) */
  130.   int ac_tbl_no;        /* AC entropy table selector (0..3) */
  131.   
  132.   /* Remaining fields should be treated as private by applications. */
  133.   
  134.   /* These values are computed during compression or decompression startup: */
  135.   /* Component's size in DCT blocks.
  136.    * Any dummy blocks added to complete an MCU are not counted; therefore
  137.    * these values do not depend on whether a scan is interleaved or not.
  138.    */
  139.   JDIMENSION width_in_blocks;
  140.   JDIMENSION height_in_blocks;
  141.   /* Size of a DCT block in samples.  Always DCTSIZE for compression.
  142.    * For decompression this is the size of the output from one DCT block,
  143.    * reflecting any scaling we choose to apply during the IDCT step.
  144.    * Values of 1,2,4,8 are likely to be supported.  Note that different
  145.    * components may receive different IDCT scalings.
  146.    */
  147.   int DCT_scaled_size;
  148.   /* The downsampled dimensions are the component's actual, unpadded number
  149.    * of samples at the main buffer (preprocessing/compression interface), thus
  150.    * downsampled_width = ceil(image_width * Hi/Hmax)
  151.    * and similarly for height.  For decompression, IDCT scaling is included, so
  152.    * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
  153.    */
  154.   JDIMENSION downsampled_width;     /* actual width in samples */
  155.   JDIMENSION downsampled_height; /* actual height in samples */
  156.   /* This flag is used only for decompression.  In cases where some of the
  157.    * components will be ignored (eg grayscale output from YCbCr image),
  158.    * we can skip most computations for the unused components.
  159.    */
  160.   boolean component_needed;    /* do we need the value of this component? */
  161.  
  162.   /* These values are computed before starting a scan of the component: */
  163.   int MCU_width;        /* number of blocks per MCU, horizontally */
  164.   int MCU_height;        /* number of blocks per MCU, vertically */
  165.   int MCU_blocks;        /* MCU_width * MCU_height */
  166.   int MCU_sample_width;        /* MCU width in samples, MCU_width*DCT_scaled_size */
  167.   int last_col_width;        /* # of non-dummy blocks across in last MCU */
  168.   int last_row_height;        /* # of non-dummy blocks down in last MCU */
  169.  
  170.   /* Private per-component storage for DCT or IDCT subsystem. */
  171.   void * dct_table;
  172. } jpeg_component_info;
  173.  
  174.  
  175. /* Known color spaces. */
  176.  
  177. typedef enum {
  178.     JCS_UNKNOWN,        /* error/unspecified */
  179.     JCS_GRAYSCALE,        /* monochrome */
  180.     JCS_RGB,        /* red/green/blue */
  181.     JCS_YCbCr,        /* Y/Cb/Cr (also known as YUV) */
  182.     JCS_CMYK,        /* C/M/Y/K */
  183.     JCS_YCCK        /* Y/Cb/Cr/K */
  184. } J_COLOR_SPACE;
  185.  
  186. /* DCT/IDCT algorithm options. */
  187.  
  188. typedef enum {
  189.     JDCT_ISLOW,        /* slow but accurate integer algorithm */
  190.     JDCT_IFAST,        /* faster, less accurate integer method */
  191.     JDCT_FLOAT        /* floating-point: accurate, fast on fast HW */
  192. } J_DCT_METHOD;
  193.  
  194. #ifndef JDCT_DEFAULT        /* may be overridden in jconfig.h */
  195. #define JDCT_DEFAULT  JDCT_ISLOW
  196. #endif
  197. #ifndef JDCT_FASTEST        /* may be overridden in jconfig.h */
  198. #define JDCT_FASTEST  JDCT_IFAST
  199. #endif
  200.  
  201. /* Dithering options for decompression. */
  202.  
  203. typedef enum {
  204.     JDITHER_NONE,        /* no dithering */
  205.     JDITHER_ORDERED,    /* simple ordered dither */
  206.     JDITHER_FS        /* Floyd-Steinberg error diffusion dither */
  207. } J_DITHER_MODE;
  208.  
  209.  
  210. /* Common fields between JPEG compression and decompression master structs. */
  211.  
  212. #define jpeg_common_fields \
  213.   struct jpeg_error_mgr * err;    /* Error handler module */\
  214.   struct jpeg_memory_mgr * mem;    /* Memory manager module */\
  215.   struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  216.   boolean is_decompressor;    /* so common code can tell which is which */\
  217.   int global_state        /* for checking call sequence validity */
  218.  
  219. /* Routines that are to be used by both halves of the library are declared
  220.  * to receive a pointer to this structure.  There are no actual instances of
  221.  * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
  222.  */
  223. struct jpeg_common_struct {
  224.   jpeg_common_fields;        /* Fields common to both master struct types */
  225.   /* Additional fields follow in an actual jpeg_compress_struct or
  226.    * jpeg_decompress_struct.  All three structs must agree on these
  227.    * initial fields!  (This would be a lot cleaner in C++.)
  228.    */
  229. };
  230.  
  231. typedef struct jpeg_common_struct * j_common_ptr;
  232. typedef struct jpeg_compress_struct * j_compress_ptr;
  233. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  234.  
  235.  
  236. /* Master record for a compression instance */
  237.  
  238. struct jpeg_compress_struct {
  239.   jpeg_common_fields;        /* Fields shared with jpeg_decompress_struct */
  240.  
  241.   /* Destination for compressed data */
  242.   struct jpeg_destination_mgr * dest;
  243.  
  244.   /* Description of source image --- these fields must be filled in by
  245.    * outer application before starting compression.  in_color_space must
  246.    * be correct before you can even call jpeg_set_defaults().
  247.    */
  248.  
  249.   JDIMENSION image_width;    /* input image width */
  250.   JDIMENSION image_height;    /* input image height */
  251.   int input_components;        /* # of color components in input image */
  252.   J_COLOR_SPACE in_color_space;    /* colorspace of input image */
  253.  
  254.   double input_gamma;        /* image gamma of input image */
  255.  
  256.   /* Compression parameters --- these fields must be set before calling
  257.    * jpeg_start_compress().  We recommend calling jpeg_set_defaults() to
  258.    * initialize everything to reasonable defaults, then changing anything
  259.    * the application specifically wants to change.  That way you won't get
  260.    * burnt when new parameters are added.  Also note that there are several
  261.    * helper routines to simplify changing parameters.
  262.    */
  263.  
  264.   int data_precision;        /* bits of precision in image data */
  265.  
  266.   int num_components;        /* # of color components in JPEG image */
  267.   J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  268.  
  269.   jpeg_component_info * comp_info;
  270.   /* comp_info[i] describes component that appears i'th in SOF */
  271.   
  272.   JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  273.   /* ptrs to coefficient quantization tables, or NULL if not defined */
  274.   
  275.   JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  276.   JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  277.   /* ptrs to Huffman coding tables, or NULL if not defined */
  278.   
  279.   UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  280.   UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  281.   UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  282.  
  283.   boolean raw_data_in;        /* TRUE=caller supplies downsampled data */
  284.   boolean arith_code;        /* TRUE=arithmetic coding, FALSE=Huffman */
  285.   boolean interleave;        /* TRUE=interleaved output, FALSE=not */
  286.   boolean optimize_coding;    /* TRUE=optimize entropy encoding parms */
  287.   boolean CCIR601_sampling;    /* TRUE=first samples are cosited */
  288.   int smoothing_factor;        /* 1..100, or 0 for no input smoothing */
  289.   J_DCT_METHOD dct_method;    /* DCT algorithm selector */
  290.  
  291.   /* The restart interval can be specified in absolute MCUs by setting
  292.    * restart_interval, or in MCU rows by setting restart_in_rows
  293.    * (in which case the correct restart_interval will be figured
  294.    * for each scan).
  295.    */
  296.   unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  297.   int restart_in_rows;        /* if > 0, MCU rows per restart interval */
  298.  
  299.   /* Parameters controlling emission of special markers. */
  300.  
  301.   boolean write_JFIF_header;    /* should a JFIF marker be written? */
  302.   /* These three values are not used by the JPEG code, merely copied */
  303.   /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */
  304.   /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */
  305.   /* ratio is defined by X_density/Y_density even when density_unit=0. */
  306.   UINT8 density_unit;        /* JFIF code for pixel size units */
  307.   UINT16 X_density;        /* Horizontal pixel density */
  308.   UINT16 Y_density;        /* Vertical pixel density */
  309.   boolean write_Adobe_marker;    /* should an Adobe marker be written? */
  310.   
  311.   /* State variable: index of next scanline to be written to
  312.    * jpeg_write_scanlines().  Application may use this to control its
  313.    * processing loop, e.g., "while (next_scanline < image_height)".
  314.    */
  315.  
  316.   JDIMENSION next_scanline;    /* 0 .. image_height-1  */
  317.  
  318.   /* Remaining fields are known throughout compressor, but generally
  319.    * should not be touched by a surrounding application.
  320.    */
  321.  
  322.   /*
  323.    * These fields are computed during compression startup
  324.    */
  325.   int max_h_samp_factor;    /* largest h_samp_factor */
  326.   int max_v_samp_factor;    /* largest v_samp_factor */
  327.  
  328.   JDIMENSION total_iMCU_rows;    /* # of iMCU rows to be input to coef ctlr */
  329.   /* The coefficient controller receives data in units of MCU rows as defined
  330.    * for fully interleaved scans (whether the JPEG file is interleaved or not).
  331.    * There are v_samp_factor * DCTSIZE sample rows of each component in an
  332.    * "iMCU" (interleaved MCU) row.
  333.    */
  334.   
  335.   /*
  336.    * These fields are valid during any one scan.
  337.    * They describe the components and MCUs actually appearing in the scan.
  338.    */
  339.   int comps_in_scan;        /* # of JPEG components in this scan */
  340.   jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  341.   /* *cur_comp_info[i] describes component that appears i'th in SOS */
  342.   
  343.   JDIMENSION MCUs_per_row;    /* # of MCUs across the image */
  344.   JDIMENSION MCU_rows_in_scan;    /* # of MCU rows in the image */
  345.   
  346.   int blocks_in_MCU;        /* # of DCT blocks per MCU */
  347.   int MCU_membership[MAX_BLOCKS_IN_MCU];
  348.   /* MCU_membership[i] is index in cur_comp_info of component owning */
  349.   /* i'th block in an MCU */
  350.  
  351.   /*
  352.    * Links to compression subobjects (methods and private variables of modules)
  353.    */
  354.   struct jpeg_comp_master * master;
  355.   struct jpeg_c_main_controller * main;
  356.   struct jpeg_c_prep_controller * prep;
  357.   struct jpeg_c_coef_controller * coef;
  358.   struct jpeg_marker_writer * marker;
  359.   struct jpeg_color_converter * cconvert;
  360.   struct jpeg_downsampler * downsample;
  361.   struct jpeg_forward_dct * fdct;
  362.   struct jpeg_entropy_encoder * entropy;
  363. };
  364.  
  365.  
  366. /* Master record for a decompression instance */
  367.  
  368. struct jpeg_decompress_struct {
  369.   jpeg_common_fields;        /* Fields shared with jpeg_compress_struct */
  370.  
  371.   /* Source of compressed data */
  372.   struct jpeg_source_mgr * src;
  373.  
  374.   /* Basic description of image --- filled in by jpeg_read_header(). */
  375.   /* Application may inspect these values to decide how to process image. */
  376.  
  377.   JDIMENSION image_width;    /* nominal image width (from SOF marker) */
  378.   JDIMENSION image_height;    /* nominal image height */
  379.   int num_components;        /* # of color components in JPEG image */
  380.   J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  381.  
  382.   /* Decompression processing parameters --- these fields must be set before
  383.    * calling jpeg_start_decompress().  Note that jpeg_read_header() initializes
  384.    * them to default values.
  385.    */
  386.  
  387.   J_COLOR_SPACE out_color_space; /* colorspace for output */
  388.  
  389.   unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  390.  
  391.   double output_gamma;        /* image gamma wanted in output */
  392.  
  393.   boolean raw_data_out;        /* TRUE=downsampled data wanted */
  394.  
  395.   boolean quantize_colors;    /* TRUE=colormapped output wanted */
  396.   /* the following are ignored if not quantize_colors: */
  397.   boolean two_pass_quantize;    /* TRUE=use two-pass color quantization */
  398.   J_DITHER_MODE dither_mode;    /* type of color dithering to use */
  399.   int desired_number_of_colors;    /* max number of colors to use */
  400.  
  401.   J_DCT_METHOD dct_method;    /* DCT algorithm selector */
  402.   boolean do_fancy_upsampling;    /* TRUE=apply fancy upsampling */
  403.  
  404.   /* Description of actual output image that will be returned to application.
  405.    * These fields are computed by jpeg_start_decompress().
  406.    * You can also use jpeg_calc_output_dimensions() to determine these values
  407.    * in advance of calling jpeg_start_decompress().
  408.    */
  409.  
  410.   JDIMENSION output_width;    /* scaled image width */
  411.   JDIMENSION output_height;    /* scaled image height */
  412.   int out_color_components;    /* # of color components in out_color_space */
  413.   int output_components;    /* # of color components returned */
  414.   /* output_components is 1 (a colormap index) when quantizing colors;
  415.    * otherwise it equals out_color_components.
  416.    */
  417.   int rec_outbuf_height;    /* min recommended height of scanline buffer */
  418.   /* If the buffer passed to jpeg_read_scanlines() is less than this many rows
  419.    * high, space and time will be wasted due to unnecessary data copying.
  420.    * Usually rec_outbuf_height will be 1 or 2, at most 4.
  421.    */
  422.  
  423.   /* When quantizing colors, the output colormap is described by these fields.
  424.    * The application can supply a colormap by setting colormap non-NULL before
  425.    * calling jpeg_start_decompress; otherwise a colormap is created during
  426.    * jpeg_start_decompress.
  427.    * The map has out_color_components rows and actual_number_of_colors columns.
  428.    */
  429.   int actual_number_of_colors;    /* number of entries in use */
  430.   JSAMPARRAY colormap;        /* The color map as a 2-D pixel array */
  431.  
  432.   /* State variable: index of next scaled scanline to be read from
  433.    * jpeg_read_scanlines().  Application may use this to control its
  434.    * processing loop, e.g., "while (output_scanline < output_height)".
  435.    */
  436.  
  437.   JDIMENSION output_scanline;    /* 0 .. output_height-1  */
  438.  
  439.   /* Internal JPEG parameters --- the application usually need not look at
  440.    * these fields.
  441.    */
  442.  
  443.   /* Quantization and Huffman tables are carried forward across input
  444.    * datastreams when processing abbreviated JPEG datastreams.
  445.    */
  446.  
  447.   JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  448.   /* ptrs to coefficient quantization tables, or NULL if not defined */
  449.  
  450.   JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  451.   JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  452.   /* ptrs to Huffman coding tables, or NULL if not defined */
  453.  
  454.   /* These parameters are never carried across datastreams, since they
  455.    * are given in SOF/SOS markers or defined to be reset by SOI.
  456.    */
  457.  
  458.   int data_precision;        /* bits of precision in image data */
  459.  
  460.   jpeg_component_info * comp_info;
  461.   /* comp_info[i] describes component that appears i'th in SOF */
  462.  
  463.   UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  464.   UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  465.   UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  466.  
  467.   boolean arith_code;        /* TRUE=arithmetic coding, FALSE=Huffman */
  468.  
  469.   unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  470.  
  471.   /* These fields record data obtained from optional markers recognized by
  472.    * the JPEG library.
  473.    */
  474.   boolean saw_JFIF_marker;    /* TRUE iff a JFIF APP0 marker was found */
  475.   /* Data copied from JFIF marker: */
  476.   UINT8 density_unit;        /* JFIF code for pixel size units */
  477.   UINT16 X_density;        /* Horizontal pixel density */
  478.   UINT16 Y_density;        /* Vertical pixel density */
  479.   boolean saw_Adobe_marker;    /* TRUE iff an Adobe APP14 marker was found */
  480.   UINT8 Adobe_transform;    /* Color transform code from Adobe marker */
  481.  
  482.   boolean CCIR601_sampling;    /* TRUE=first samples are cosited */
  483.  
  484.   /* Remaining fields are known throughout decompressor, but generally
  485.    * should not be touched by a surrounding application.
  486.    */
  487.  
  488.   /*
  489.    * These fields are computed during decompression startup
  490.    */
  491.   int max_h_samp_factor;    /* largest h_samp_factor */
  492.   int max_v_samp_factor;    /* largest v_samp_factor */
  493.  
  494.   int min_DCT_scaled_size;    /* smallest DCT_scaled_size of any component */
  495.  
  496.   JDIMENSION total_iMCU_rows;    /* # of iMCU rows to be output by coef ctlr */
  497.   /* The coefficient controller outputs data in units of MCU rows as defined
  498.    * for fully interleaved scans (whether the JPEG file is interleaved or not).
  499.    * There are v_samp_factor * DCT_scaled_size sample rows of each component
  500.    * in an "iMCU" (interleaved MCU) row.
  501.    */
  502.  
  503.   JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  504.  
  505.   /*
  506.    * These fields are valid during any one scan.
  507.    * They describe the components and MCUs actually appearing in the scan.
  508.    */
  509.   int comps_in_scan;        /* # of JPEG components in this scan */
  510.   jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  511.   /* *cur_comp_info[i] describes component that appears i'th in SOS */
  512.  
  513.   JDIMENSION MCUs_per_row;    /* # of MCUs across the image */
  514.   JDIMENSION MCU_rows_in_scan;    /* # of MCU rows in the image */
  515.  
  516.   int blocks_in_MCU;        /* # of DCT blocks per MCU */
  517.   int MCU_membership[MAX_BLOCKS_IN_MCU];
  518.   /* MCU_membership[i] is index in cur_comp_info of component owning */
  519.   /* i'th block in an MCU */
  520.  
  521.   /* This field is shared between entropy decoder and marker parser.
  522.    * It is either zero or the code of a JPEG marker that has been
  523.    * read from the data source, but has not yet been processed.
  524.    */
  525.   int unread_marker;
  526.  
  527.   /*
  528.    * Links to decompression subobjects (methods, private variables of modules)
  529.    */
  530.   struct jpeg_decomp_master * master;
  531.   struct jpeg_d_main_controller * main;
  532.   struct jpeg_d_coef_controller * coef;
  533.   struct jpeg_d_post_controller * post;
  534.   struct jpeg_marker_reader * marker;
  535.   struct jpeg_entropy_decoder * entropy;
  536.   struct jpeg_inverse_dct * idct;
  537.   struct jpeg_upsampler * upsample;
  538.   struct jpeg_color_deconverter * cconvert;
  539.   struct jpeg_color_quantizer * cquantize;
  540. };
  541.  
  542.  
  543. /* "Object" declarations for JPEG modules that may be supplied or called
  544.  * directly by the surrounding application.
  545.  * As with all objects in the JPEG library, these structs only define the
  546.  * publicly visible methods and state variables of a module.  Additional
  547.  * private fields may exist after the public ones.
  548.  */
  549.  
  550.  
  551. /* Error handler object */
  552.  
  553. struct jpeg_error_mgr {
  554.   /* Error exit handler: does not return to caller */
  555.   JMETHOD(void, error_exit, (j_common_ptr cinfo));
  556.   /* Conditionally emit a trace or warning message */
  557.   JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  558.   /* Routine that actually outputs a trace or error message */
  559.   JMETHOD(void, output_message, (j_common_ptr cinfo));
  560.   /* Format a message string for the most recent JPEG error or message */
  561.   JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  562. #define JMSG_LENGTH_MAX  200    /* recommended size of format_message buffer */
  563.   /* Reset error state variables at start of a new image */
  564.   JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  565.   
  566.   /* The message ID code and any parameters are saved here.
  567.    * A message can have one string parameter or up to 8 int parameters.
  568.    */
  569.   int msg_code;
  570. #define JMSG_STR_PARM_MAX  80
  571.   union {
  572.     int i[8];
  573.     char s[JMSG_STR_PARM_MAX];
  574.   } msg_parm;
  575.   
  576.   /* Standard state variables for error facility */
  577.   
  578.   int trace_level;        /* max msg_level that will be displayed */
  579.   
  580.   /* For recoverable corrupt-data errors, we emit a warning message,
  581.    * but keep going unless emit_message chooses to abort.  emit_message
  582.    * should count warnings in num_warnings.  The surrounding application
  583.    * can check for bad data by seeing if num_warnings is nonzero at the
  584.    * end of processing.
  585.    */
  586.   long num_warnings;        /* number of corrupt-data warnings */
  587.  
  588.   /* These fields point to the table(s) of error message strings.
  589.    * An application can change the table pointer to switch to a different
  590.    * message list (typically, to change the language in which errors are
  591.    * reported).  Some applications may wish to add additional error codes
  592.    * that will be handled by the JPEG library error mechanism; the second
  593.    * table pointer is used for this purpose.
  594.    *
  595.    * First table includes all errors generated by JPEG library itself.
  596.    * Error code 0 is reserved for a "no such error string" message.
  597.    */
  598.   const char * const * jpeg_message_table; /* Library errors */
  599.   int last_jpeg_message;    /* Table contains strings 0..last_jpeg_message */
  600.   /* Second table can be added by application (see cjpeg/djpeg for example).
  601.    * It contains strings numbered first_addon_message..last_addon_message.
  602.    */
  603.   const char * const * addon_message_table; /* Non-library errors */
  604.   int first_addon_message;    /* code for first string in addon table */
  605.   int last_addon_message;    /* code for last string in addon table */
  606. };
  607.  
  608.  
  609. /* Progress monitor object */
  610.  
  611. struct jpeg_progress_mgr {
  612.   JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  613.  
  614.   long pass_counter;        /* work units completed in this pass */
  615.   long pass_limit;        /* total number of work units in this pass */
  616.   int completed_passes;        /* passes completed so far */
  617.   int total_passes;        /* total number of passes expected */
  618. };
  619.  
  620.  
  621. /* Data destination object for compression */
  622.  
  623. struct jpeg_destination_mgr {
  624.   JOCTET * next_output_byte;    /* => next byte to write in buffer */
  625.   size_t free_in_buffer;    /* # of byte spaces remaining in buffer */
  626.  
  627.   JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  628.   JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  629.   JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  630. };
  631.  
  632.  
  633. /* Data source object for decompression */
  634.  
  635. struct jpeg_source_mgr {
  636.   const JOCTET * next_input_byte; /* => next byte to read from buffer */
  637.   size_t bytes_in_buffer;    /* # of bytes remaining in buffer */
  638.  
  639.   JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  640.   JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  641.   JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  642.   JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo));
  643.   JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  644. };
  645.  
  646.  
  647. /* Memory manager object.
  648.  * Allocates "small" objects (a few K total), "large" objects (tens of K),
  649.  * and "really big" objects (virtual arrays with backing store if needed).
  650.  * The memory manager does not allow individual objects to be freed; rather,
  651.  * each created object is assigned to a pool, and whole pools can be freed
  652.  * at once.  This is faster and more convenient than remembering exactly what
  653.  * to free, especially where malloc()/free() are not too speedy.
  654.  * NB: alloc routines never return NULL.  They exit to error_exit if not
  655.  * successful.
  656.  */
  657.  
  658. #define JPOOL_PERMANENT    0    /* lasts until master record is destroyed */
  659. #define JPOOL_IMAGE    1    /* lasts until done with image/datastream */
  660. #define JPOOL_NUMPOOLS    2
  661.  
  662. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  663. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  664.  
  665.  
  666. struct jpeg_memory_mgr {
  667.   /* Method pointers */
  668.   JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  669.                 size_t sizeofobject));
  670.   JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  671.                      size_t sizeofobject));
  672.   JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  673.                      JDIMENSION samplesperrow,
  674.                      JDIMENSION numrows));
  675.   JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  676.                       JDIMENSION blocksperrow,
  677.                       JDIMENSION numrows));
  678.   JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  679.                           int pool_id,
  680.                           JDIMENSION samplesperrow,
  681.                           JDIMENSION numrows,
  682.                           JDIMENSION unitheight));
  683.   JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  684.                           int pool_id,
  685.                           JDIMENSION blocksperrow,
  686.                           JDIMENSION numrows,
  687.                           JDIMENSION unitheight));
  688.   JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  689.   JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  690.                        jvirt_sarray_ptr ptr,
  691.                        JDIMENSION start_row,
  692.                        boolean writable));
  693.   JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  694.                         jvirt_barray_ptr ptr,
  695.                         JDIMENSION start_row,
  696.                         boolean writable));
  697.   JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  698.   JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  699.  
  700.   /* Limit on memory allocation for this JPEG object.  (Note that this is
  701.    * merely advisory, not a guaranteed maximum; it only affects the space
  702.    * used for virtual-array buffers.)  May be changed by outer application
  703.    * after creating the JPEG object.
  704.    */
  705.   long max_memory_to_use;
  706. };
  707.  
  708.  
  709. /* Routine signature for application-supplied marker processing methods.
  710.  * Need not pass marker code since it is stored in cinfo->unread_marker.
  711.  */
  712. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  713.  
  714.  
  715. /* Declarations for routines called by application.
  716.  * The JPP macro hides prototype parameters from compilers that can't cope.
  717.  * Note JPP requires double parentheses.
  718.  */
  719.  
  720. #ifdef HAVE_PROTOTYPES
  721. #define JPP(arglist)    arglist
  722. #else
  723. #define JPP(arglist)    ()
  724. #endif
  725.  
  726.  
  727. /* Short forms of external names for systems with brain-damaged linkers.
  728.  * We shorten external names to be unique in the first six letters, which
  729.  * is good enough for all known systems.
  730.  * (If your compiler itself needs names to be unique in less than 15 
  731.  * characters, you are out of luck.  Get a better compiler.)
  732.  */
  733.  
  734. #ifdef NEED_SHORT_EXTERNAL_NAMES
  735. #define jpeg_std_error        jStdError
  736. #define jpeg_create_compress    jCreaCompress
  737. #define jpeg_create_decompress    jCreaDecompress
  738. #define jpeg_destroy_compress    jDestCompress
  739. #define jpeg_destroy_decompress    jDestDecompress
  740. #define jpeg_stdio_dest        jStdDest
  741. #define jpeg_stdio_src        jStdSrc
  742. #define jpeg_set_defaults    jSetDefaults
  743. #define jpeg_set_colorspace    jSetColorspace
  744. #define jpeg_default_colorspace    jDefColorspace
  745. #define jpeg_set_quality    jSetQuality
  746. #define jpeg_set_linear_quality    jSetLQuality
  747. #define jpeg_add_quant_table    jAddQuantTable
  748. #define jpeg_quality_scaling    jQualityScaling
  749. #define jpeg_suppress_tables    jSuppressTables
  750. #define jpeg_alloc_quant_table    jAlcQTable
  751. #define jpeg_alloc_huff_table    jAlcHTable
  752. #define jpeg_start_compress    jStrtCompress
  753. #define jpeg_write_scanlines    jWrtScanlines
  754. #define jpeg_finish_compress    jFinCompress
  755. #define jpeg_write_raw_data    jWrtRawData
  756. #define jpeg_write_marker    jWrtMarker
  757. #define jpeg_write_tables    jWrtTables
  758. #define jpeg_read_header    jReadHeader
  759. #define jpeg_start_decompress    jStrtDecompress
  760. #define jpeg_read_scanlines    jReadScanlines
  761. #define jpeg_finish_decompress    jFinDecompress
  762. #define jpeg_read_raw_data    jReadRawData
  763. #define jpeg_calc_output_dimensions    jCalcDimensions
  764. #define jpeg_set_marker_processor    jSetMarker
  765. #define jpeg_abort_compress    jAbrtCompress
  766. #define jpeg_abort_decompress    jAbrtDecompress
  767. #define jpeg_abort        jAbort
  768. #define jpeg_destroy        jDestroy
  769. #define jpeg_resync_to_restart    jResyncRestart
  770. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  771.  
  772.  
  773. /* Default error-management setup */
  774. EXTERN struct jpeg_error_mgr *jpeg_std_error JPP((struct jpeg_error_mgr *err));
  775.  
  776. /* Initialization and destruction of JPEG compression objects */
  777. /* NB: you must set up the error-manager BEFORE calling jpeg_create_xxx */
  778. EXTERN void jpeg_create_compress JPP((j_compress_ptr cinfo));
  779. EXTERN void jpeg_create_decompress JPP((j_decompress_ptr cinfo));
  780. EXTERN void jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  781. EXTERN void jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  782.  
  783. /* Standard data source and destination managers: stdio streams. */
  784. /* Caller is responsible for opening the file before and closing after. */
  785. EXTERN void jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  786. EXTERN void jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  787.  
  788. /* Default parameter setup for compression */
  789. EXTERN void jpeg_set_defaults JPP((j_compress_ptr cinfo));
  790. /* Compression parameter setup aids */
  791. EXTERN void jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  792.                      J_COLOR_SPACE colorspace));
  793. EXTERN void jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  794. EXTERN void jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  795.                   boolean force_baseline));
  796. EXTERN void jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  797.                      int scale_factor,
  798.                      boolean force_baseline));
  799. EXTERN void jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  800.                       const unsigned int *basic_table,
  801.                       int scale_factor,
  802.                       boolean force_baseline));
  803. EXTERN int jpeg_quality_scaling JPP((int quality));
  804. EXTERN void jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  805.                       boolean suppress));
  806. EXTERN JQUANT_TBL * jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  807. EXTERN JHUFF_TBL * jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  808.  
  809. /* Main entry points for compression */
  810. EXTERN void jpeg_start_compress JPP((j_compress_ptr cinfo,
  811.                      boolean write_all_tables));
  812. EXTERN JDIMENSION jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  813.                         JSAMPARRAY scanlines,
  814.                         JDIMENSION num_lines));
  815. EXTERN void jpeg_finish_compress JPP((j_compress_ptr cinfo));
  816.  
  817. /* Replaces jpeg_write_scanlines when writing raw downsampled data. */
  818. EXTERN JDIMENSION jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  819.                        JSAMPIMAGE data,
  820.                        JDIMENSION num_lines));
  821.  
  822. /* Write a special marker.  See libjpeg.doc concerning safe usage. */
  823. EXTERN void jpeg_write_marker JPP((j_compress_ptr cinfo, int marker,
  824.                    const JOCTET *dataptr, unsigned int datalen));
  825.  
  826. /* Alternate compression function: just write an abbreviated table file */
  827. EXTERN void jpeg_write_tables JPP((j_compress_ptr cinfo));
  828.  
  829. /* Decompression startup: read start of JPEG datastream to see what's there */
  830. EXTERN int jpeg_read_header JPP((j_decompress_ptr cinfo,
  831.                  boolean require_image));
  832. /* Return value is one of: */
  833. #define JPEG_HEADER_OK        0 /* Found valid image datastream */
  834. #define JPEG_HEADER_TABLES_ONLY    1 /* Found valid table-specs-only datastream */
  835. #define JPEG_SUSPENDED        2 /* Had to suspend before end of headers */
  836. /* If you pass require_image = TRUE (normal case), you need not check for
  837.  * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
  838.  * JPEG_SUSPENDED is only possible if you use a data source module that can
  839.  * give a suspension return (the stdio source module doesn't).
  840.  */
  841.  
  842. /* Main entry points for decompression */
  843. EXTERN void jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  844. EXTERN JDIMENSION jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  845.                        JSAMPARRAY scanlines,
  846.                        JDIMENSION max_lines));
  847. EXTERN boolean jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  848.  
  849. /* Replaces jpeg_read_scanlines when reading raw downsampled data. */
  850. EXTERN JDIMENSION jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  851.                       JSAMPIMAGE data,
  852.                       JDIMENSION max_lines));
  853.  
  854. /* Precalculate output dimensions for current decompression parameters. */
  855. EXTERN void jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  856.  
  857. /* Install a special processing method for COM or APPn markers. */
  858. EXTERN void jpeg_set_marker_processor JPP((j_decompress_ptr cinfo,
  859.                        int marker_code,
  860.                        jpeg_marker_parser_method routine));
  861.  
  862. /* If you choose to abort compression or decompression before completing
  863.  * jpeg_finish_(de)compress, then you need to clean up to release memory,
  864.  * temporary files, etc.  You can just call jpeg_destroy_(de)compress
  865.  * if you're done with the JPEG object, but if you want to clean it up and
  866.  * reuse it, call this:
  867.  */
  868. EXTERN void jpeg_abort_compress JPP((j_compress_ptr cinfo));
  869. EXTERN void jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  870.  
  871. /* Generic versions of jpeg_abort and jpeg_destroy that work on either
  872.  * flavor of JPEG object.  These may be more convenient in some places.
  873.  */
  874. EXTERN void jpeg_abort JPP((j_common_ptr cinfo));
  875. EXTERN void jpeg_destroy JPP((j_common_ptr cinfo));
  876.  
  877. /* Default restart-marker-resync procedure for use by data source modules */
  878. EXTERN boolean jpeg_resync_to_restart JPP((j_decompress_ptr cinfo));
  879.  
  880.  
  881. /* These marker codes are exported since applications and data source modules
  882.  * are likely to want to use them.
  883.  */
  884.  
  885. #define JPEG_RST0    0xD0    /* RST0 marker code */
  886. #define JPEG_EOI    0xD9    /* EOI marker code */
  887. #define JPEG_APP0    0xE0    /* APP0 marker code */
  888. #define JPEG_COM    0xFE    /* COM marker code */
  889.  
  890.  
  891. /* If we have a brain-damaged compiler that emits warnings (or worse, errors)
  892.  * for structure definitions that are never filled in, keep it quiet by
  893.  * supplying dummy definitions for the various substructures.
  894.  */
  895.  
  896. #ifdef INCOMPLETE_TYPES_BROKEN
  897. #ifndef JPEG_INTERNALS        /* will be defined in jpegint.h */
  898. struct jvirt_sarray_control { long dummy; };
  899. struct jvirt_barray_control { long dummy; };
  900. struct jpeg_comp_master { long dummy; };
  901. struct jpeg_c_main_controller { long dummy; };
  902. struct jpeg_c_prep_controller { long dummy; };
  903. struct jpeg_c_coef_controller { long dummy; };
  904. struct jpeg_marker_writer { long dummy; };
  905. struct jpeg_color_converter { long dummy; };
  906. struct jpeg_downsampler { long dummy; };
  907. struct jpeg_forward_dct { long dummy; };
  908. struct jpeg_entropy_encoder { long dummy; };
  909. struct jpeg_decomp_master { long dummy; };
  910. struct jpeg_d_main_controller { long dummy; };
  911. struct jpeg_d_coef_controller { long dummy; };
  912. struct jpeg_d_post_controller { long dummy; };
  913. struct jpeg_marker_reader { long dummy; };
  914. struct jpeg_entropy_decoder { long dummy; };
  915. struct jpeg_inverse_dct { long dummy; };
  916. struct jpeg_upsampler { long dummy; };
  917. struct jpeg_color_deconverter { long dummy; };
  918. struct jpeg_color_quantizer { long dummy; };
  919. #endif /* JPEG_INTERNALS */
  920. #endif /* INCOMPLETE_TYPES_BROKEN */
  921.  
  922.  
  923. /*
  924.  * The JPEG library modules define JPEG_INTERNALS before including this file.
  925.  * The internal structure declarations are read only when that is true.
  926.  * Applications using the library should not include jpegint.h, but may wish
  927.  * to include jerror.h.
  928.  */
  929.  
  930. #ifdef JPEG_INTERNALS
  931. #include "jpegint.h"        /* fetch private declarations */
  932. #include "jerror.h"        /* fetch error codes too */
  933. #endif
  934.  
  935. #endif /* JPEGLIB_H */
  936.